﻿<c:BaseControl x:Class="personalplaner.gui.stamm.views.PlanungsJahrStamm"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:bs="clr-namespace:personalplaner.business.stamm;assembly=personalplaner.business"
             xmlns:vm="clr-namespace:personalplaner.common.mvvm.factory;assembly=personalplaner.common"
             xmlns:fac="clr-namespace:personalplaner.gui.stamm.viewmodels.factories"
             vm:ViewModelLoader.FactoryType="{x:Type fac:PlanungsJahrStammModelFactory}"
             xmlns:c="clr-namespace:personalplaner.common.controls;assembly=personalplaner.common"
             xmlns:conv="clr-namespace:personalplaner.common.converters;assembly=personalplaner.common"
             xmlns:p="clr-namespace:personalplaner.gui.Properties"
             Background="Transparent"
             Foreground="#E1000000">

    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/personalplaner.common;component/resources/styles/WhiteStyleTemplates.xaml"/>
                <ResourceDictionary>
                    <conv:DateTimeToIsoConverter x:Key="dateToIso"/>
                    <conv:BoolInvertConverter x:Key="boolInvert"/>
                    <BooleanToVisibilityConverter x:Key="boolToVis"/>
                    <conv:BoolToInvertVisibilityConverter x:Key="boolInvVis"/>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Control.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Border BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Margin="5,5,5,0" Padding="5" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition />
                </Grid.RowDefinitions>
                
                <CheckBox IsChecked="{Binding IsOldYear}" Margin="20,0,0,0">
                    <TextBlock Text="{x:Static p:Resources.BestehendeJahreBearbeiten}"/>
                </CheckBox>
                <ListBox ItemsSource="{Binding ExistingYears}" SelectedItem="{Binding SelectedExistingYear}" IsEnabled="{Binding IsOldYear}" Margin="40,20,0,0" Grid.Row="1">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Jahr}" x:Name="txt" Foreground="Black" />
                            
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding Status}" Value="Inactive">
                                    <Setter TargetName="txt" Property="Foreground" Value="Gray"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Grid>
            
        </Border>

        <GridSplitter Width="4" Margin="0,10,0,5" Background="Transparent"/>

        <GroupBox Margin="5,10,40,5" Grid.Column="1">

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition />
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                
                <Grid Margin="0,0,0,50">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition Width="*" MaxWidth="300"/>
                        <ColumnDefinition Width="Auto" MaxWidth="300"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="{x:Static p:Resources.Jahr}" FontWeight="Heavy" IsEnabled="{Binding IsOldYear, Converter={StaticResource boolInvert}}"/>
                    <ComboBox ItemsSource="{Binding Years}" SelectedItem="{Binding SelectedYear}" SelectedIndex="{Binding SelectedYearIndex}" Grid.Column="1" IsEnabled="{Binding IsOldYear, Converter={StaticResource boolInvert}}" Validation.ErrorTemplate="{x:Null}"/>

                    <TextBlock Text="{x:Static p:Resources.Zeitraum}" Grid.Row="1" FontWeight="Heavy"/>
                    <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1" Margin="2,3,0,3" >
                        <TextBlock Text="{Binding Von, Converter={StaticResource dateToIso}}"/>
                        <TextBlock Text="-" Margin="5,0,5,0"/>
                        <TextBlock Text="{Binding Bis, Converter={StaticResource dateToIso}}"/>
                    </StackPanel>

                    <!--<TextBlock Text="Plan Id" Grid.Row="2" FontWeight="Heavy"/>
                    <TextBlock Text="{Binding PlanId}" Grid.Row="2" Grid.Column="1" Margin="2,2,0,2"/>-->

                    <TextBlock Text="{x:Static p:Resources.PlanYearDescription}" Margin="0,50,0,0" TextWrapping="Wrap" Grid.Row="3" Grid.ColumnSpan="3"/>

                </Grid>
                
                <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Right">
                    <Button MinWidth="60" Margin="5" Command="{Binding MonthCommand}">
                        <TextBlock Text="{x:Static p:Resources.Monate}"/>
                    </Button>
                    <Button MinWidth="60" Margin="5" Command="{Binding FeiertageCommand}">
                        <TextBlock Text="{x:Static p:Resources.Feiertage}"/>
                    </Button>
                </StackPanel>
                
            </Grid>

        </GroupBox> 

        <StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,40,20">
            <Button MinWidth="60" Margin="5" Command="{Binding ActivateYearCommand}" Visibility="{Binding IsOldYear, Converter={StaticResource boolToVis}}">
                <TextBlock Text="{x:Static p:Resources.JahrAktivieren}"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding CreateYearCommand}" Visibility="{Binding IsOldYear, Converter={StaticResource boolInvVis}}">
                <TextBlock Text="{x:Static p:Resources.JahrEroeffnen}"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding NewCommand}" IsEnabled="{Binding IsOldYear}">
                <TextBlock Text="{x:Static p:Resources.New}"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsDefault="True" 
                    Command="{Binding OkCommand}">
                <TextBlock Text="{x:Static p:Resources.Ok}"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsCancel="True" 
                    Command="{Binding CancelCommand}">
                <TextBlock Text="{x:Static p:Resources.Cancel}"/>
            </Button>
        </StackPanel>

    </Grid>
    
</c:BaseControl>
